<?php
namespace app\index\controller;

use think\Controller;
use think\Session;

class Index  extends Controller
{
    public function index()
    {
        return view('login');
    }
    // public function assets()
    // {

    // }

    public function doLogin()
    {
        $data = input('get.');
        $res = model('User')->Cx($data);
        if ($res) {
            Session::set('user', $res);
            return json(array('code' => 0, 'msg' => '登录成功', 'data' => ''));
        } else {
            return json(array('code' => 1, 'msg' => 'ERROR!!!', 'data' => ''));
        }
    }

    public function showPower()
    {
        $uid = Session::get('user')['id'];
        $power = model('User')->getPower($uid);
        Session::set('power',$power);
        $arr = $this->recursion($power, 0);
        $this->assign("power", $arr);
        return view("index1");
    }

    public function recursion($power, $pid)
    {
        $arr = [];
        foreach ($power as $k => $v) {
            if ($v['pid'] == $pid) {
                $v['child'] = $this->recursion($power, $v['id']);
                $arr[] = $v;
            }
        }

        return $arr;
    }
}